package com.ourteam.product.model.service;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.ArrayUtils;

import com.alibaba.fastjson.JSON;
import com.ourteam.product.model.dao.IProductModelCodeTemplateDAO;
import com.ourteam.product.model.dao.IProductModelObjectDAO;
import com.ourteam.product.model.dao.IProductModelPropertyDAO;
import com.ourteam.product.model.dao.IProductModelServiceParameterTemplateDAO;
import com.ourteam.product.model.dao.ProductDatabase;
import com.ourteam.product.model.dao.ProductDatabaseDAOQueryBean;
import com.ourteam.product.model.dao.ProductDatabaseDataTypeMap;
import com.ourteam.product.model.dao.ProductDatabaseDataTypeMapDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelAction;
import com.ourteam.product.model.dao.ProductModelActionDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelBase;
import com.ourteam.product.model.dao.ProductModelBaseDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelBaseRelate;
import com.ourteam.product.model.dao.ProductModelBaseRelateDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelCodeTemplate;
import com.ourteam.product.model.dao.ProductModelCodeTemplateDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelDomain;
import com.ourteam.product.model.dao.ProductModelDomainDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelObject;
import com.ourteam.product.model.dao.ProductModelObjectDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelObjectRelate;
import com.ourteam.product.model.dao.ProductModelObjectRelateDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelPackage;
import com.ourteam.product.model.dao.ProductModelPackageDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelProperty;
import com.ourteam.product.model.dao.ProductModelPropertyDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelPropertyRelate;
import com.ourteam.product.model.dao.ProductModelPropertyRelateDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelService;
import com.ourteam.product.model.dao.ProductModelServiceDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelServiceFeatureRelate;
import com.ourteam.product.model.dao.ProductModelServiceFeatureRelateDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelServiceParameter;
import com.ourteam.product.model.dao.ProductModelServiceParameterDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelServiceParameterTemplate;
import com.ourteam.product.model.dao.ProductModelServiceParameterTemplateDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelServiceTemplate;
import com.ourteam.product.model.dao.ProductModelServiceTemplateDAOQueryBean;
import com.ourteam.product.model.dao.ProductModelServiceTemplateItem;
import com.ourteam.product.model.dao.ProductModelServiceTemplateItemDAOQueryBean;
import com.ourteam.product.model.domain.ProductDatabaseBean;
import com.ourteam.product.model.domain.ProductDatabaseDataTypeMapBean;
import com.ourteam.product.model.domain.ProductModelActionBean;
import com.ourteam.product.model.domain.ProductModelBaseBean;
import com.ourteam.product.model.domain.ProductModelBaseRelateBean;
import com.ourteam.product.model.domain.ProductModelCodeTemplateBean;
import com.ourteam.product.model.domain.ProductModelDomainBean;
import com.ourteam.product.model.domain.ProductModelObjectBean;
import com.ourteam.product.model.domain.ProductModelObjectRelateBean;
import com.ourteam.product.model.domain.ProductModelPackageBean;
import com.ourteam.product.model.domain.ProductModelPropertyBean;
import com.ourteam.product.model.domain.ProductModelPropertyRelateBean;
import com.ourteam.product.model.domain.ProductModelRelateTypeEnum;
import com.ourteam.product.model.domain.ProductModelServiceBean;
import com.ourteam.product.model.domain.ProductModelServiceFeatureRelateBean;
import com.ourteam.product.model.domain.ProductModelServiceParameterBean;
import com.ourteam.product.model.domain.ProductModelServiceParameterTemplateBean;
import com.ourteam.product.model.domain.ProductModelServiceParameterTypeEnum;
import com.ourteam.product.model.domain.ProductModelServiceTemplateBean;
import com.ourteam.product.model.domain.ProductModelServiceTemplateItemBean;
import com.ourteam.product.model.domain.ProductModelTypeEnum;
import com.ourteam.system.domain.SystemEventLogBean;
import com.ourteam.system.domain.SystemUser;

import net.dao.SQLFunctionUtils;
import net.service.GeneralDataStatusEnum;

public class ProductModelServiceImpl extends AbstractProductModelService {

	/**
	 * 
	 * 
	 * @param productModelDomain
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected void doAddNewProductModelDomain(
			final com.ourteam.product.model.domain.ProductModelDomainBean productModelDomain) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelDomain.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelDomain.getSubmitterId());
			productModelDomain.setCreatorName(systemUser.getName());
			productModelDomain.setCreateTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		this.productModelDomainDao.insert(productModelDomain.convertToProductModelDomain());

		systemEventLog.setEventOperatorId(productModelDomain.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelDomain, true));
		systemEventLog.setEventSource("ProductModelDomain");

		systemEventLog.setEventSourceId(productModelDomain.getId());

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型域");

		eventContent.put("dataDesc", productModelDomain.getDomainName());

		this.systemEventLogService.addSystemEventLog("ADD_NEW_DATA", systemEventLog, eventContent);
	}

	/**
	 * 
	 * 
	 * @param productModelDomain
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected void doModifyProductModelDomain(
			final com.ourteam.product.model.domain.ProductModelDomainBean productModelDomain) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelDomain.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelDomain.getSubmitterId());
			productModelDomain.setLastModifierName(systemUser.getName());
			productModelDomain.setLastModifyTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		this.productModelDomainDao.update(productModelDomain.convertToProductModelDomain());

		systemEventLog.setEventSourceId(productModelDomain.getId());
		systemEventLog.setEventOperatorId(productModelDomain.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelDomain, true));
		systemEventLog.setEventSource("ProductModelDomain");

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型域");

		eventContent.put("dataDesc", productModelDomain.getDomainName());

		this.systemEventLogService.addSystemEventLog("MODIFY_DATA", systemEventLog, eventContent);
	}

	/**
	 * 
	 * 
	 * @param productModelDomainIds
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected void doDeleteProductModelDomains(final long[] productModelDomainIds) throws Exception {

		ProductModelDomainDAOQueryBean queryBean = new ProductModelDomainDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelDomainIds);

		this.productModelDomainDao.delete(queryBean);

	}

	/**
	 * 
	 * 
	 * @param productModelDomainId
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected com.ourteam.product.model.domain.ProductModelDomainBean doGetProductModelDomainById(
			final long productModelDomainId) throws Exception {

		ProductModelDomain modelDomain = this.productModelDomainDao.findById(productModelDomainId);

		return modelDomain != null ? new ProductModelDomainBean(modelDomain) : null;
	}

	/**
	 * 
	 * 
	 * @param queryBean
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected com.ourteam.product.model.domain.ProductModelDomainBean[] doQueryProductModelDomains(
			final com.ourteam.product.model.dao.ProductModelDomainDAOQueryBean queryBean) throws Exception {

		return ProductModelDomainBean.toArray(this.productModelDomainDao.query(queryBean));
	}

	/**
	 * 
	 * 
	 * @param queryBean
	 * 
	 * @model
	 * @throws BusinessErrorException
	 * @throws Exception
	 */
	protected int doQueryProductModelDomainCount(
			final com.ourteam.product.model.dao.ProductModelDomainDAOQueryBean queryBean) throws Exception {

		return this.productModelDomainDao.queryCount(queryBean);

	}

	@Override
	protected void doAddNewProductModelPackage(ProductModelPackageBean productModelPackage) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelPackage.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelPackage.getSubmitterId());
			productModelPackage.setCreatorName(systemUser.getName());
			productModelPackage.setCreateTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		this.productModelPackageDao.insert(productModelPackage.convertToProductModelPackage());

		systemEventLog.setEventOperatorId(productModelPackage.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelPackage, true));
		systemEventLog.setEventSource("ProductModelPackage");

		systemEventLog.setEventSourceId(productModelPackage.getId());

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型包");

		eventContent.put("dataDesc", productModelPackage.getPackageName());

		this.systemEventLogService.addSystemEventLog("ADD_NEW_DATA", systemEventLog, eventContent);

	}

	@Override
	protected void doModifyProductModelPackage(ProductModelPackageBean productModelPackage) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelPackage.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelPackage.getSubmitterId());
			productModelPackage.setLastModifierName(systemUser.getName());
			productModelPackage.setLastModifyTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		this.productModelPackageDao.update(productModelPackage.convertToProductModelPackage());

		ProductModelObjectDAOQueryBean queryBean = new ProductModelObjectDAOQueryBean();

		queryBean.createCriteria().andPackageIdEqualTo(productModelPackage.getId());

		queryBean.addUpdateProperty(IProductModelObjectDAO.ObjectCode,
				SQLFunctionUtils.concatFunction(new String[] { "'" + productModelPackage.getPackageName() + "'", "'.'",
						IProductModelObjectDAO.ObjectName }, this.productModelObjectDao));

		this.productModelObjectDao.update(queryBean);

		systemEventLog.setEventSourceId(productModelPackage.getId());
		systemEventLog.setEventOperatorId(productModelPackage.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelPackage, true));
		systemEventLog.setEventSource("ProductModelPackage");

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型包");

		eventContent.put("dataDesc", productModelPackage.getPackageName());

		this.systemEventLogService.addSystemEventLog("MODIFY_DATA", systemEventLog, eventContent);

	}

	@Override
	protected void doDeleteProductModelPackages(long[] productModelPackageIds) throws Exception {

		if (ArrayUtils.isEmpty(productModelPackageIds)) {
			return;
		}

		ProductModelPackageDAOQueryBean queryBean = new ProductModelPackageDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelPackageIds);

		this.productModelPackageDao.delete(queryBean);

	}

	@Override
	protected ProductModelPackageBean doGetProductModelPackageById(long productModelPackageId) throws Exception {

		ProductModelPackage modelPackage = this.productModelPackageDao.findById(productModelPackageId);

		return modelPackage != null ? new ProductModelPackageBean(modelPackage) : null;
	}

	@Override
	protected ProductModelPackageBean[] doQueryProductModelPackages(ProductModelPackageDAOQueryBean queryBean)
			throws Exception {

		return ProductModelPackageBean.toArray(this.productModelPackageDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelPackageCount(ProductModelPackageDAOQueryBean queryBean) throws Exception {

		return this.productModelPackageDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductDatabase(ProductDatabaseBean productDatabase) throws Exception {

		this.productDatabaseDao.insert(productDatabase.convertToProductDatabase());
	}

	@Override
	protected void doModifyProductDatabase(ProductDatabaseBean productDatabase) throws Exception {

		this.productDatabaseDao.update(productDatabase.convertToProductDatabase());

	}

	@Override
	protected void doDeleteProductDatabases(long[] productDatabaseIds) throws Exception {

		if (ArrayUtils.isEmpty(productDatabaseIds)) {
			return;
		}

		ProductDatabaseDAOQueryBean queryBean = new ProductDatabaseDAOQueryBean();

		queryBean.createCriteria().andIdIn(productDatabaseIds);

		this.productDatabaseDao.delete(queryBean);

	}

	@Override
	protected ProductDatabaseBean doGetProductDatabaseById(long productDatabaseId) throws Exception {

		ProductDatabase productDatabase = this.productDatabaseDao.findById(productDatabaseId);

		return productDatabase != null ? new ProductDatabaseBean(productDatabase) : null;
	}

	@Override
	protected ProductDatabaseBean[] doQueryProductDatabases(ProductDatabaseDAOQueryBean queryBean) throws Exception {

		return ProductDatabaseBean.toArray(this.productDatabaseDao.query(queryBean));
	}

	@Override
	protected int doQueryProductDatabaseCount(ProductDatabaseDAOQueryBean queryBean) throws Exception {

		return this.productDatabaseDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductModelObject(ProductModelObjectBean productModelObjectBean) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelObjectBean.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelObjectBean.getSubmitterId());
			productModelObjectBean.setCreatorName(systemUser.getName());
			productModelObjectBean.setCreateTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		if (productModelObjectBean.getPackageId() != 0) {

			ProductModelPackage modelPackage = productModelPackageDao.findById(productModelObjectBean.getPackageId());

			productModelObjectBean
					.setObjectCode(modelPackage.getPackageName() + "." + productModelObjectBean.getObjectName());
		} else {
			productModelObjectBean.setObjectCode(productModelObjectBean.getObjectName());
		}

		this.productModelObjectDao.insert(productModelObjectBean.convertToProductModelObject());

		systemEventLog.setEventOperatorId(productModelObjectBean.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelObjectBean, true));
		systemEventLog.setEventSource("ProductModelObject");

		systemEventLog.setEventSourceId(productModelObjectBean.getId());

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型对象");

		eventContent.put("dataDesc", productModelObjectBean.getObjectName());

		this.systemEventLogService.addSystemEventLog("ADD_NEW_DATA", systemEventLog, eventContent);

	}

	@Override
	protected void doModifyProductModelObject(ProductModelObjectBean productModelObjectBean) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelObjectBean.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelObjectBean.getSubmitterId());
			productModelObjectBean.setLastModifierName(systemUser.getName());
			productModelObjectBean.setLastModifyTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		if (productModelObjectBean.getPackageId() != 0) {
			ProductModelPackage modelPackage = productModelPackageDao.findById(productModelObjectBean.getPackageId());

			productModelObjectBean
					.setObjectCode(modelPackage.getPackageName() + "." + productModelObjectBean.getObjectName());
		} else {
			productModelObjectBean.setObjectCode(productModelObjectBean.getObjectName());
		}

		this.productModelObjectDao.update(productModelObjectBean.convertToProductModelObject());

		if (productModelObjectBean.getObjectType().equals(ProductModelTypeEnum.DAO.getName())) {

			ProductModelObjectRelateDAOQueryBean queryBean = new ProductModelObjectRelateDAOQueryBean();

			queryBean.createCriteria().andRelatedObjectIdEqualTo(productModelObjectBean.getId())
					.andRelatedTypeEqualTo(ProductModelRelateTypeEnum.DEPEND_DAO.getName());

			ProductModelObjectRelate[] relateBeans = this.productModelObjectRelateDao.query(queryBean);

			if (ArrayUtils.isNotEmpty(relateBeans)) {
				for (int i = 0; i < relateBeans.length; i++) {

					ProductModelObjectRelate productModelObjectRelate = relateBeans[i];

					ProductModelObject daoQueryBean = this.productModelObjectDao
							.findById(productModelObjectRelate.getObjectId());

					daoQueryBean.setSubmitterId(productModelObjectBean.getSubmitterId());

					daoQueryBean.setObjectCode(productModelObjectBean.getObjectCode() + "DAOQueryBean");
					daoQueryBean.setObjectName(productModelObjectBean.getObjectName() + "DAOQueryBean");

					daoQueryBean.setPackageId(productModelObjectBean.getPackageId());

					this.productModelObjectDao.update(daoQueryBean);
				}
			}

		}

		systemEventLog.setEventSourceId(productModelObjectBean.getId());
		systemEventLog.setEventOperatorId(productModelObjectBean.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelObjectBean, true));
		systemEventLog.setEventSource("ProductModelObject");

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型对象");

		eventContent.put("dataDesc", productModelObjectBean.getObjectName());

		this.systemEventLogService.addSystemEventLog("MODIFY_DATA", systemEventLog, eventContent);

	}

	@Override
	protected ProductModelObjectBean doGetProductModelObjectById(long productModelObjectBeanId) throws Exception {

		ProductModelObject productModelObject = this.productModelObjectDao.findById(productModelObjectBeanId);

		return productModelObject != null ? new ProductModelObjectBean(productModelObject) : null;
	}

	@Override
	protected ProductModelObjectBean[] doQueryProductModelObjects(ProductModelObjectDAOQueryBean queryBean)
			throws Exception {

		return ProductModelObjectBean.toArray(this.productModelObjectDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelObjectCount(ProductModelObjectDAOQueryBean queryBean) throws Exception {

		return this.productModelObjectDao.queryCount(queryBean);
	}

	@Override
	protected void doDeleteProductModelObjects(long[] productModelObjectBeanIds) throws Exception {

		if (ArrayUtils.isEmpty(productModelObjectBeanIds)) {
			return;
		}

		ProductModelObjectDAOQueryBean queryBean = new ProductModelObjectDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelObjectBeanIds);

		this.productModelObjectDao.deleteProductModelObjectRelate(queryBean);

		this.productModelObjectDao.deleteProductModelProperty(queryBean);

		this.productModelObjectDao.delete(queryBean);

	}

	@Override
	protected void doAddNewProductModelProperty(ProductModelPropertyBean productModelPropertyBean) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelPropertyBean.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelPropertyBean.getSubmitterId());
			productModelPropertyBean.setCreatorName(systemUser.getName());
			productModelPropertyBean.setCreateTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		ProductModelProperty modelProperty = productModelPropertyBean.convertToProductModelProperty();

		if (modelProperty.isSortIndexSetted() == false) {

			ProductModelPropertyDAOQueryBean queryBean = new ProductModelPropertyDAOQueryBean();

			queryBean.createCriteria().andObjectIdEqualTo(modelProperty.getObjectId());

			int count = this.productModelPropertyDao.queryCount(queryBean);

			modelProperty.setSortIndex(count);

		}

		this.productModelPropertyDao.insert(modelProperty);

		systemEventLog.setEventOperatorId(productModelPropertyBean.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelPropertyBean, true));
		systemEventLog.setEventSource("ProductModelProperty");

		systemEventLog.setEventSourceId(productModelPropertyBean.getId());

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型属性");

		eventContent.put("dataDesc", productModelPropertyBean.getPropertyName());

		this.systemEventLogService.addSystemEventLog("ADD_NEW_DATA", systemEventLog, eventContent);

	}

	@Override
	protected void doModifyProductModelProperty(ProductModelPropertyBean productModelPropertyBean) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelPropertyBean.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelPropertyBean.getSubmitterId());
			productModelPropertyBean.setLastModifierName(systemUser.getName());
			productModelPropertyBean.setLastModifyTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		this.productModelPropertyDao.update(productModelPropertyBean.convertToProductModelProperty());

		systemEventLog.setEventSourceId(productModelPropertyBean.getId());
		systemEventLog.setEventOperatorId(productModelPropertyBean.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelPropertyBean, true));
		systemEventLog.setEventSource("ProductModelProperty");

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型属性");

		eventContent.put("dataDesc", productModelPropertyBean.getPropertyName());

		this.systemEventLogService.addSystemEventLog("MODIFY_DATA", systemEventLog, eventContent);

	}

	@Override
	protected void doDeleteProductModelProperties(long[] productModelPropertyBeanIds) throws Exception {

		if (ArrayUtils.isEmpty(productModelPropertyBeanIds)) {
			return;
		}

		ProductModelPropertyRelateDAOQueryBean relateDAOQueryBean = new ProductModelPropertyRelateDAOQueryBean();

		relateDAOQueryBean.createCriteria().andPropertyIdIn(productModelPropertyBeanIds);

		relateDAOQueryBean.or(relateDAOQueryBean.createCriteria().andRelatedPropertyIdIn(productModelPropertyBeanIds));

		this.productModelPropertyRelateDao.delete(relateDAOQueryBean);

		ProductModelPropertyDAOQueryBean queryBean = new ProductModelPropertyDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelPropertyBeanIds);

		this.productModelPropertyDao.delete(queryBean);

	}

	@Override
	protected ProductModelPropertyBean doGetProductModelPropertyById(long productModelPropertyBeanId) throws Exception {

		ProductModelProperty modelProperty = this.productModelPropertyDao.findById(productModelPropertyBeanId);

		return modelProperty != null ? new ProductModelPropertyBean(modelProperty) : null;
	}

	@Override
	protected ProductModelPropertyBean[] doQueryProductModelProperties(ProductModelPropertyDAOQueryBean queryBean)
			throws Exception {

		return ProductModelPropertyBean.toArray(this.productModelPropertyDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelPropertyCount(ProductModelPropertyDAOQueryBean queryBean) throws Exception {

		return this.productModelPropertyDao.queryCount(queryBean);
	}

	@Override
	protected ProductModelPropertyBean[] doGetProductPropertiesByObjectId(long productModelObjectId) throws Exception {

		ProductModelPropertyDAOQueryBean queryBean = new ProductModelPropertyDAOQueryBean();

		queryBean.createCriteria().andObjectIdEqualTo(productModelObjectId);

		queryBean.setSortProperty(IProductModelPropertyDAO.SortIndex);

		return queryProductModelProperties(queryBean);
	}

	@Override
	protected void doAddNewProductModelObjectRelate(ProductModelObjectRelateBean productModelObjectRelateBean)
			throws Exception {

		this.productModelObjectRelateDao.insert(productModelObjectRelateBean.convertToProductModelObjectRelate());

	}

	@Override
	protected void doDeleteProductModelObjectRelates(long[] productModelObjectRelateBeanIds) throws Exception {

		ProductModelObjectRelateDAOQueryBean queryBean = new ProductModelObjectRelateDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelObjectRelateBeanIds);

		ProductModelPropertyRelateDAOQueryBean propertyRelateDAOQueryBean = new ProductModelPropertyRelateDAOQueryBean();

		propertyRelateDAOQueryBean.createCriteria().andObjectRelatedIdIn(productModelObjectRelateBeanIds);

		this.productModelPropertyRelateDao.delete(propertyRelateDAOQueryBean);

		this.productModelObjectRelateDao.delete(queryBean);

	}

	@Override
	protected ProductModelObjectRelateBean doGetProductModelObjectRelateById(long productModelObjectRelateId)
			throws Exception {

		ProductModelObjectRelate objectRelate = this.productModelObjectRelateDao.findById(productModelObjectRelateId);

		return objectRelate != null ? new ProductModelObjectRelateBean(objectRelate) : null;
	}

	@Override
	protected ProductModelObjectRelateBean[] doQueryProductModelObjectRelates(
			ProductModelObjectRelateDAOQueryBean queryBean) throws Exception {

		return ProductModelObjectRelateBean.toArray(this.productModelObjectRelateDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelObjectRelateCount(ProductModelObjectRelateDAOQueryBean queryBean)
			throws Exception {

		return this.productModelObjectRelateDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductModelPropertyRelates(ProductModelPropertyRelateBean[] productModelPropertyRelateBeans)
			throws Exception {

		ProductModelPropertyRelate[] propertyRelates = new ProductModelPropertyRelate[productModelPropertyRelateBeans.length];

		for (int i = 0; i < propertyRelates.length; i++) {
			propertyRelates[i] = productModelPropertyRelateBeans[i].convertToProductModelPropertyRelate();
		}

		this.productModelPropertyRelateDao.batchInsert(propertyRelates);

	}

	@Override
	protected void doModifyProductModelPropertyRelate(ProductModelPropertyRelateBean productModelPropertyRelateBean)
			throws Exception {

		this.productModelPropertyRelateDao.update(productModelPropertyRelateBean.convertToProductModelPropertyRelate());

	}

	@Override
	protected void doDeleteProductModelPropertyRelates(long[] productModelPropertyRelateIds) throws Exception {

		ProductModelPropertyRelateDAOQueryBean queryBean = new ProductModelPropertyRelateDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelPropertyRelateIds);

		this.productModelPropertyRelateDao.delete(queryBean);

	}

	@Override
	protected ProductModelPropertyRelateBean doGetProductModelPropertyRelateById(long productModelPropertyRelateId)
			throws Exception {

		ProductModelPropertyRelate propertyRelate = this.productModelPropertyRelateDao
				.findById(productModelPropertyRelateId);

		return propertyRelate != null ? new ProductModelPropertyRelateBean(propertyRelate) : null;
	}

	@Override
	protected ProductModelPropertyRelateBean[] doQueryProductModelPropertyRelates(
			ProductModelPropertyRelateDAOQueryBean queryBean) throws Exception {

		return ProductModelPropertyRelateBean.toArray(this.productModelPropertyRelateDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelPropertyRelateCount(ProductModelPropertyRelateDAOQueryBean queryBean)
			throws Exception {

		return this.productModelPropertyRelateDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductModelService(ProductModelServiceBean productModelServiceBean) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelServiceBean.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelServiceBean.getSubmitterId());
			productModelServiceBean.setCreatorName(systemUser.getName());
			productModelServiceBean.setCreateTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		this.productModelServiceDao.insert(productModelServiceBean.convertToProductModelService());

		systemEventLog.setEventOperatorId(productModelServiceBean.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelServiceBean, true));
		systemEventLog.setEventSource("ProductModelService");

		systemEventLog.setEventSourceId(productModelServiceBean.getId());

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型服务");

		eventContent.put("dataDesc", productModelServiceBean.getServiceName());

		this.systemEventLogService.addSystemEventLog("ADD_NEW_DATA", systemEventLog, eventContent);

	}

	@Override
	protected void doModifyProductModelService(ProductModelServiceBean productModelServiceBean) throws Exception {

		SystemEventLogBean systemEventLog = new SystemEventLogBean();

		if (productModelServiceBean.getSubmitterId() != 0) {
			SystemUser systemUser = this.sysUserService.getSysUserById(productModelServiceBean.getSubmitterId());
			productModelServiceBean.setLastModifierName(systemUser.getName());
			productModelServiceBean.setLastModifyTime(new Date());
			systemEventLog.setEventOperator(systemUser.getName());
		}

		this.productModelServiceDao.update(productModelServiceBean.convertToProductModelService());

		systemEventLog.setEventSourceId(productModelServiceBean.getId());
		systemEventLog.setEventOperatorId(productModelServiceBean.getSubmitterId());
		systemEventLog.setEventData(JSON.toJSONString(productModelServiceBean, true));
		systemEventLog.setEventSource("ProductModelService");

		Map<String, String> eventContent = new HashMap<String, String>();

		eventContent.put("dataType", "模型服务");

		eventContent.put("dataDesc", productModelServiceBean.getServiceName());

		this.systemEventLogService.addSystemEventLog("MODIFY_DATA", systemEventLog, eventContent);

	}

	@Override
	protected void doDeleteProductModelServices(long[] productModelServiceIds) throws Exception {

		ProductModelServiceDAOQueryBean queryBean = new ProductModelServiceDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelServiceIds);

		this.productModelServiceDao.delete(queryBean);

	}

	@Override
	protected ProductModelServiceBean doGetProductModelServiceById(long productModelServiceId) throws Exception {

		ProductModelService productModelService = this.productModelServiceDao.findById(productModelServiceId);

		return productModelService != null ? new ProductModelServiceBean(productModelService) : null;
	}

	@Override
	protected ProductModelServiceBean[] doQueryProductModelServices(ProductModelServiceDAOQueryBean queryBean)
			throws Exception {

		return ProductModelServiceBean.toArray(this.productModelServiceDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelServiceCount(ProductModelServiceDAOQueryBean queryBean) throws Exception {

		return this.productModelServiceDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductModelServiceParameter(
			ProductModelServiceParameterBean productModelServiceParameterBean) throws Exception {

		this.productModelServiceParameterDao
				.insert(productModelServiceParameterBean.convertToProductModelServiceParameter());

	}

	@Override
	protected void doModifyProductModelServiceParameter(
			ProductModelServiceParameterBean productModelServiceParameterBean) throws Exception {

		this.productModelServiceParameterDao
				.update(productModelServiceParameterBean.convertToProductModelServiceParameter());

	}

	@Override
	protected void doDeleteProductModelServiceParameters(long[] productModelServiceParameterIds) throws Exception {

		ProductModelServiceParameterDAOQueryBean queryBean = new ProductModelServiceParameterDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelServiceParameterIds);

		this.productModelServiceParameterDao.delete(queryBean);

	}

	@Override
	protected ProductModelServiceParameterBean doGetProductModelServiceParameterById(
			long productModelServiceParameterId) throws Exception {

		ProductModelServiceParameter modelServiceParameter = this.productModelServiceParameterDao
				.findById(productModelServiceParameterId);

		return modelServiceParameter != null ? new ProductModelServiceParameterBean(modelServiceParameter) : null;
	}

	@Override
	protected ProductModelServiceParameterBean[] doQueryProductModelServiceParameters(
			ProductModelServiceParameterDAOQueryBean queryBean) throws Exception {

		return ProductModelServiceParameterBean.toArray(this.productModelServiceParameterDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelServiceParameterCount(ProductModelServiceParameterDAOQueryBean queryBean)
			throws Exception {

		return this.productModelServiceParameterDao.queryCount(queryBean);
	}

	@Override
	protected void doSetProductModelServiceParameters(long serviceId, ProductModelServiceParameterBean[] parameters)
			throws Exception {

		ProductModelServiceParameterDAOQueryBean queryBean = new ProductModelServiceParameterDAOQueryBean();

		queryBean.createCriteria().andServiceIdEqualTo(serviceId);

		ProductModelServiceParameter[] datas = new ProductModelServiceParameter[parameters.length];

		int index = 0;

		for (int i = 0; i < datas.length; i++) {
			datas[i] = parameters[i].convertToProductModelServiceParameter();
			datas[i].setServiceId(serviceId);
			if (ProductModelServiceParameterTypeEnum.INPUT.getName().equals(datas[i].getParameterType())) {
				datas[i].setSortIndex(index++);
			}
		}

		productModelServiceParameterDao.synchronize(datas, queryBean);

	}

	@Override
	protected ProductModelPropertyBean[] doGetProductModelObjectProperties(long objectId) throws Exception {

		ProductModelPropertyDAOQueryBean queryBean = new ProductModelPropertyDAOQueryBean();

		queryBean.createCriteria().andObjectIdEqualTo(objectId);

		queryBean.setSortProperty(IProductModelPropertyDAO.SortIndex);

		return queryProductModelProperties(queryBean);
	}

	@Override
	protected ProductModelPropertyRelateBean[] doGetProductModelPropertyRelates(long propertyModelObjectRelateId)
			throws Exception {

		ProductModelPropertyRelateDAOQueryBean queryBean = new ProductModelPropertyRelateDAOQueryBean();

		queryBean.createCriteria().andObjectRelatedIdEqualTo(propertyModelObjectRelateId);

		return queryProductModelPropertyRelates(queryBean);
	}

	@Override
	protected void doSetProductModelObjectRelated(ProductModelObjectRelateBean productModelObjectRelateBean,
			ProductModelPropertyRelateBean[] productModelPropertyRelateBean) throws Exception {

		if (productModelObjectRelateBean.getId() == 0) {
			this.productModelObjectRelateDao.insert(productModelObjectRelateBean.convertToProductModelObjectRelate());
		} else {
			this.productModelObjectRelateDao.update(productModelObjectRelateBean.convertToProductModelObjectRelate());
		}

		ProductModelPropertyRelate[] propertyRelates = new ProductModelPropertyRelate[productModelPropertyRelateBean.length];

		for (int i = 0; i < propertyRelates.length; i++) {
			propertyRelates[i] = productModelPropertyRelateBean[i].convertToProductModelPropertyRelate();
			propertyRelates[i].setObjectRelatedId(productModelObjectRelateBean.getId());
			propertyRelates[i].setRelatedType(productModelObjectRelateBean.getRelatedType());
		}

		ProductModelPropertyRelateDAOQueryBean queryBean = new ProductModelPropertyRelateDAOQueryBean();

		queryBean.createCriteria().andObjectRelatedIdEqualTo(productModelObjectRelateBean.getId())
				.andRelatedTypeEqualTo(productModelObjectRelateBean.getRelatedType());

		this.productModelPropertyRelateDao.synchronize(propertyRelates, queryBean);

	}

	@Override
	protected ProductModelPropertyBean[] doGetProductModelRelatedPropertiesByType(long productModelObjectId,
			ProductModelRelateTypeEnum[] relateTypeEnums) throws Exception {

		String[] types = new String[relateTypeEnums.length];

		for (int i = 0; i < types.length; i++) {
			types[i] = relateTypeEnums[i].getName();

		}

		ProductModelPropertyRelateDAOQueryBean subQueryBean = new ProductModelPropertyRelateDAOQueryBean();

		subQueryBean.createCriteria().andPropertyObjectIdEqualTo(productModelObjectId).andRelatedTypeIn(types);

		subQueryBean.addPropertyIdSelectProperty();

		ProductModelPropertyDAOQueryBean queryBean = new ProductModelPropertyDAOQueryBean();

		queryBean.createCriteria().andObjectIdEqualTo(productModelObjectId).andIdIn(subQueryBean,
				productModelPropertyRelateDao);

		return queryProductModelProperties(queryBean);
	}

	@Override
	protected ProductModelPropertyBean[] doGetProductModelNotRelatedPropertiesByType(long productModelObjectId,
			ProductModelRelateTypeEnum[] relateTypeEnums) throws Exception {

		String[] types = new String[relateTypeEnums.length];

		for (int i = 0; i < types.length; i++) {
			types[i] = relateTypeEnums[i].getName();

		}

		ProductModelPropertyRelateDAOQueryBean subQueryBean = new ProductModelPropertyRelateDAOQueryBean();

		subQueryBean.createCriteria().andPropertyObjectIdEqualTo(productModelObjectId).andRelatedTypeIn(types);

		subQueryBean.addPropertyIdSelectProperty();

		ProductModelPropertyDAOQueryBean queryBean = new ProductModelPropertyDAOQueryBean();

		queryBean.createCriteria().andObjectIdEqualTo(productModelObjectId).andIdNotIn(subQueryBean,
				productModelPropertyRelateDao);

		return queryProductModelProperties(queryBean);

	}

	@Override
	protected ProductModelObjectBean[] doGetRelatedProductModelObjects(long productModelObjectId,
			ProductModelRelateTypeEnum[] relateTypeEnums) throws Exception {

		String[] relateTypes = new String[relateTypeEnums.length];

		for (int i = 0; i < relateTypes.length; i++) {
			relateTypes[i] = relateTypeEnums[i].getName();
		}

		ProductModelObjectDAOQueryBean queryBean = new ProductModelObjectDAOQueryBean();

		ProductModelObjectRelateDAOQueryBean subQueryBean = new ProductModelObjectRelateDAOQueryBean();

		subQueryBean.addRelatedObjectIdSelectProperty();

		subQueryBean.createCriteria().andObjectIdEqualTo(productModelObjectId).andRelatedTypeIn(relateTypes);

		queryBean.createCriteria().andIdIn(subQueryBean, productModelObjectRelateDao);

		return queryProductModelObjects(queryBean);
	}

	@Override
	protected void doSetProductModelPropertySort(long[] propertyIds) throws Exception {

		ProductModelProperty[] productModelProperties = new ProductModelProperty[propertyIds.length];

		for (int i = 0; i < propertyIds.length; i++) {

			productModelProperties[i] = this.productModelPropertyDao.findById(propertyIds[i]);

			productModelProperties[i].setSortIndex(i);

		}

		this.productModelPropertyDao.batchUpdate(productModelProperties);

	}

	@Override
	protected void doSetProductModelObjectRelateSort(long[] objectRelateIds) throws Exception {

		ProductModelObjectRelate[] updateObjects = new ProductModelObjectRelate[objectRelateIds.length];

		for (int i = 0; i < objectRelateIds.length; i++) {

			updateObjects[i] = this.productModelObjectRelateDao.findById(objectRelateIds[i]);

			updateObjects[i].setSortIndex(i);

		}

		this.productModelObjectRelateDao.batchUpdate(updateObjects);

	}

	@Override
	protected boolean doCanDeleteProductModelObject(long productModelObjectId) throws Exception {

		ProductModelObjectRelateDAOQueryBean queryBean = new ProductModelObjectRelateDAOQueryBean();

		queryBean.createCriteria().andRelatedObjectIdEqualTo(productModelObjectId);

		int relatedCount = this.productModelObjectRelateDao.queryCount(queryBean);

		ProductModelPropertyDAOQueryBean propertyQueryBean = new ProductModelPropertyDAOQueryBean();

		propertyQueryBean.createCriteria().andDataTypeIdEqualTo(productModelObjectId);

		relatedCount = relatedCount + this.productModelPropertyDao.queryCount(propertyQueryBean);

		ProductModelServiceParameterDAOQueryBean parameterDAOQueryBean = new ProductModelServiceParameterDAOQueryBean();

		parameterDAOQueryBean.createCriteria().andDataTypeIdEqualTo(productModelObjectId);

		relatedCount = relatedCount + this.productModelServiceParameterDao.queryCount(parameterDAOQueryBean);

		return relatedCount == 0;
	}

	@Override
	protected void doAddNewProductModelServiceTemplate(ProductModelServiceTemplateBean productModelServiceTemplate)
			throws Exception {

		this.productModelServiceTemplateDao.insert(productModelServiceTemplate.convertToProductModelServiceTemplate());

	}

	@Override
	protected void doModifyProductModelServiceTemplate(ProductModelServiceTemplateBean productModelServiceTemplate)
			throws Exception {

		this.productModelServiceTemplateDao.update(productModelServiceTemplate.convertToProductModelServiceTemplate());

	}

	@Override
	protected void doDeleteProductModelServiceTemplates(long[] productModelServiceTemplateIds) throws Exception {

		ProductModelServiceTemplateDAOQueryBean queryBean = new ProductModelServiceTemplateDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelServiceTemplateIds);

		this.productModelServiceTemplateDao.delete(queryBean);

	}

	@Override
	protected ProductModelServiceTemplateBean[] doQueryProductModelServiceTemplates(
			ProductModelServiceTemplateDAOQueryBean queryBean) throws Exception {

		return ProductModelServiceTemplateBean.toArray(this.productModelServiceTemplateDao.query(queryBean));

	}

	@Override
	protected int doQueryProductModelServiceTemplateCount(ProductModelServiceTemplateDAOQueryBean queryBean)
			throws Exception {
		return this.productModelServiceTemplateDao.queryCount(queryBean);
	}

	@Override
	protected ProductModelServiceTemplateBean doGetProductModelServiceTemplateById(long productModelServiceTemplateId)
			throws Exception {

		ProductModelServiceTemplate modelServiceTemplate = this.productModelServiceTemplateDao
				.findById(productModelServiceTemplateId);

		return modelServiceTemplate != null ? new ProductModelServiceTemplateBean(modelServiceTemplate) : null;
	}

	@Override
	protected void doAddNewProductModelServiceTemplateItem(
			ProductModelServiceTemplateItemBean productModelServiceTemplateItem) throws Exception {
		this.productModelServiceTemplateItemDao
				.insert(productModelServiceTemplateItem.convertToProductModelServiceTemplateItem());

	}

	@Override
	protected void doModifyProductModelServiceTemplateItem(
			ProductModelServiceTemplateItemBean productModelServiceTemplateItem) throws Exception {

		this.productModelServiceTemplateItemDao
				.update(productModelServiceTemplateItem.convertToProductModelServiceTemplateItem());

	}

	@Override
	protected void doDeleteProductModelServiceTemplateItems(long[] productModelServiceTemplateItemIds)
			throws Exception {

		ProductModelServiceTemplateItemDAOQueryBean queryBean = new ProductModelServiceTemplateItemDAOQueryBean();

		queryBean.createCriteria().andIdIn(productModelServiceTemplateItemIds);

		this.productModelServiceTemplateItemDao.delete(queryBean);

	}

	@Override
	protected ProductModelServiceTemplateItemBean doGetProductModelServiceTemplateItemById(
			long productModelServiceTemplateItemId) throws Exception {

		ProductModelServiceTemplateItem templateItem = this.productModelServiceTemplateItemDao
				.findById(productModelServiceTemplateItemId);

		return templateItem != null ? new ProductModelServiceTemplateItemBean(templateItem) : null;

	}

	@Override
	protected ProductModelServiceTemplateItemBean[] doQueryProductModelServiceTemplateItems(
			ProductModelServiceTemplateItemDAOQueryBean queryBean) throws Exception {
		return ProductModelServiceTemplateItemBean.toArray(this.productModelServiceTemplateItemDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelServiceTemplateItemCount(ProductModelServiceTemplateItemDAOQueryBean queryBean)
			throws Exception {

		return this.productModelServiceTemplateItemDao.queryCount(queryBean);
	}

	@Override
	protected void doSetProductModelServiceParameterTemplates(long serviceTemplateItemId,
			ProductModelServiceParameterTemplateBean[] serviceParameterTemplates) throws Exception {

		ProductModelServiceParameterTemplateDAOQueryBean queryBean = new ProductModelServiceParameterTemplateDAOQueryBean();

		queryBean.createCriteria().andServiceTemplateItemIdEqualTo(serviceTemplateItemId);

		ProductModelServiceParameterTemplate[] datas = new ProductModelServiceParameterTemplate[serviceParameterTemplates.length];

		int index = 0;

		for (int i = 0; i < datas.length; i++) {
			datas[i] = serviceParameterTemplates[i].convertToProductModelServiceParameterTemplate();
			datas[i].setServiceTemplateItemId(serviceTemplateItemId);
			if (ProductModelServiceParameterTypeEnum.INPUT.getName().equals(datas[i].getParameterType())) {
				datas[i].setSortIndex(index++);
			}
		}

		productModelServiceParameterTemplateDao.synchronize(datas, queryBean);

	}

	@Override
	protected ProductModelServiceParameterTemplateBean[] doGetProductModelServiceTemplateItemParameters(
			long productModelServiceTemplateItemId) throws Exception {

		ProductModelServiceParameterTemplateDAOQueryBean queryBean = new ProductModelServiceParameterTemplateDAOQueryBean();

		queryBean.createCriteria().andServiceTemplateItemIdEqualTo(productModelServiceTemplateItemId);

		queryBean.setSortProperty(IProductModelServiceParameterTemplateDAO.SortIndex);

		return ProductModelServiceParameterTemplateBean
				.toArray(this.productModelServiceParameterTemplateDao.query(queryBean));
	}

	@Override
	protected void doAddNewProductDatabaseDataTypeMap(ProductDatabaseDataTypeMapBean aProductDatabaseDataTypeMap)
			throws Exception {

		this.productDatabaseDataTypeMapDao.insert(aProductDatabaseDataTypeMap.convertToProductDatabaseDataTypeMap());
	}

	@Override
	protected void doModifyProductDatabaseDataTypeMap(ProductDatabaseDataTypeMapBean aProductDatabaseDataTypeMap)
			throws Exception {

		this.productDatabaseDataTypeMapDao.update(aProductDatabaseDataTypeMap.convertToProductDatabaseDataTypeMap());

	}

	@Override
	protected ProductDatabaseDataTypeMapBean[] doQueryProductDatabaseDataTypeMaps(
			ProductDatabaseDataTypeMapDAOQueryBean queryBean) throws Exception {

		return ProductDatabaseDataTypeMapBean.toArray(this.productDatabaseDataTypeMapDao.query(queryBean));
	}

	@Override
	protected int doQueryProductDatabaseDataTypeMapCount(ProductDatabaseDataTypeMapDAOQueryBean queryBean)
			throws Exception {

		return this.productDatabaseDataTypeMapDao.queryCount(queryBean);
	}

	@Override
	protected ProductDatabaseDataTypeMapBean doGetProductDatabaseDataTypeMapById(long aProductDatabaseDataTypeMapId)
			throws Exception {

		ProductDatabaseDataTypeMap dataTypeMap = this.productDatabaseDataTypeMapDao
				.findById(aProductDatabaseDataTypeMapId);
		return dataTypeMap != null ? new ProductDatabaseDataTypeMapBean(dataTypeMap) : null;
	}

	@Override
	protected Map<String, String> doGetProductDatabaseDataTypeMaps() throws Exception {

		ProductDatabaseDataTypeMapDAOQueryBean queryBean = new ProductDatabaseDataTypeMapDAOQueryBean();

		ProductDatabaseDataTypeMap[] dataTypeMaps = this.productDatabaseDataTypeMapDao.query(queryBean);

		Map<String, String> datatypeMap = new HashMap<String, String>();

		for (int i = 0; i < dataTypeMaps.length; i++) {
			ProductDatabaseDataTypeMap productDatabaseDataTypeMap = dataTypeMaps[i];
			datatypeMap.put(productDatabaseDataTypeMap.getDataType(), productDatabaseDataTypeMap.getMappedDataType());
		}

		return datatypeMap;
	}

	@Override
	protected void doDeleteProductDatabaseDataTypeMaps(long[] aProductDatabaseDataTypeMapIds) throws Exception {

		ProductDatabaseDataTypeMapDAOQueryBean queryBean = new ProductDatabaseDataTypeMapDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductDatabaseDataTypeMapIds);

		this.productDatabaseDataTypeMapDao.delete(queryBean);

	}

	@Override
	protected void doModifyProductModelObjectRelate(ProductModelObjectRelateBean aProductModelObjectRelate)
			throws Exception {

		this.productModelObjectRelateDao.update(aProductModelObjectRelate.convertToProductModelObjectRelate());

	}

	@Override
	protected void doAddNewProductModelCodeTemplate(ProductModelCodeTemplateBean aProductModelCodeTemplate)
			throws Exception {

		ProductModelCodeTemplate codeTemplate = aProductModelCodeTemplate.convertToProductModelCodeTemplate();

		codeTemplate.setTemplateCode(codeTemplate.getTemplateName() + System.currentTimeMillis());

		codeTemplate.setStatus("active");

		codeTemplate.setTemplateVersion(1);

		this.productModelCodeTemplateDao.insert(codeTemplate);

	}

	@Override
	protected void doModifyProductModelCodeTemplate(ProductModelCodeTemplateBean aProductModelCodeTemplate)
			throws Exception {

		this.productModelCodeTemplateDao.update(aProductModelCodeTemplate.convertToProductModelCodeTemplate());

	}

	@Override
	protected void doDeleteProductModelCodeTemplates(long[] aProductModelCodeTemplateIds) throws Exception {

		ProductModelCodeTemplateDAOQueryBean queryBean = new ProductModelCodeTemplateDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductModelCodeTemplateIds);

		this.productModelCodeTemplateDao.delete(queryBean);

	}

	@Override
	protected ProductModelCodeTemplateBean doGetProductModelCodeTemplateById(long aProductModelCodeTemplateId)
			throws Exception {

		ProductModelCodeTemplate codeTemplate = this.productModelCodeTemplateDao.findById(aProductModelCodeTemplateId);

		return codeTemplate != null ? new ProductModelCodeTemplateBean(codeTemplate) : null;
	}

	@Override
	protected ProductModelCodeTemplateBean[] doQueryProductModelCodeTemplates(
			ProductModelCodeTemplateDAOQueryBean queryBean) throws Exception {

		return ProductModelCodeTemplateBean.toArray(this.productModelCodeTemplateDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelCodeTemplateCount(ProductModelCodeTemplateDAOQueryBean queryBean)
			throws Exception {

		return this.productModelCodeTemplateDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductModelCodeTemplateVersion(String templateCode,
			ProductModelCodeTemplateBean aProductModelCodeTemplate) throws Exception {

		ProductModelCodeTemplate codeTemplate = aProductModelCodeTemplate.convertToProductModelCodeTemplate();

		codeTemplate.setTemplateCode(templateCode);

		codeTemplate.setStatus(GeneralDataStatusEnum.DEACTIVE.getName());

		ProductModelCodeTemplateDAOQueryBean queryBean = new ProductModelCodeTemplateDAOQueryBean();

		queryBean.createCriteria().andTemplateCodeEqualTo(codeTemplate.getTemplateCode());

		queryBean.setSortProperty(IProductModelCodeTemplateDAO.TemplateVersion);

		ProductModelCodeTemplate[] codeTemplates = this.productModelCodeTemplateDao.query(queryBean);

		if (ArrayUtils.isNotEmpty(codeTemplates)) {

			codeTemplate.setTemplateVersion(codeTemplates[codeTemplates.length - 1].getTemplateVersion() + 1);

		} else {
			codeTemplate.setTemplateVersion(1);
		}

		this.productModelCodeTemplateDao.insert(codeTemplate);

	}

	@Override
	protected void doSwitchProductModelCodeTemplateVersion(long productModelCodeTemplateId) throws Exception {

		ProductModelCodeTemplate codeTemplate = this.productModelCodeTemplateDao.findById(productModelCodeTemplateId);

		ProductModelCodeTemplateDAOQueryBean queryBean = new ProductModelCodeTemplateDAOQueryBean();

		queryBean.createCriteria().andTemplateCodeEqualTo(codeTemplate.getTemplateCode());

		queryBean.setSortProperty(IProductModelCodeTemplateDAO.TemplateVersion);

		ProductModelCodeTemplate[] codeTemplates = this.productModelCodeTemplateDao.query(queryBean);

		if (ArrayUtils.isNotEmpty(codeTemplates)) {

			ProductModelCodeTemplate data = new ProductModelCodeTemplate();

			data.setStatus(GeneralDataStatusEnum.DEACTIVE.getName());

			this.productModelCodeTemplateDao.update(data, queryBean);
		}

		codeTemplate.setStatus(GeneralDataStatusEnum.ACTIVE.getName());

		this.productModelCodeTemplateDao.update(codeTemplate);

	}

	@Override
	protected void doAddNewProductModelServiceFeatureRelate(
			ProductModelServiceFeatureRelateBean aProductModelServiceFeatureRelate) throws Exception {

		this.productModelServiceFeatureRelateDao
				.insert(aProductModelServiceFeatureRelate.convertToProductModelServiceFeatureRelate());

	}

	@Override
	protected void doModifyProductModelServiceFeatureRelate(
			ProductModelServiceFeatureRelateBean aProductModelServiceFeatureRelate) throws Exception {

		this.productModelServiceFeatureRelateDao
				.update(aProductModelServiceFeatureRelate.convertToProductModelServiceFeatureRelate());

	}

	@Override
	protected ProductModelServiceFeatureRelateBean doGetProductModelServiceFeatureRelateById(
			long aProductModelServiceFeatureRelateId) throws Exception {

		ProductModelServiceFeatureRelate modelServiceFeatureRelate = this.productModelServiceFeatureRelateDao
				.findById(aProductModelServiceFeatureRelateId);

		return modelServiceFeatureRelate != null ? new ProductModelServiceFeatureRelateBean(modelServiceFeatureRelate)
				: null;
	}

	@Override
	protected void doDeleteProductModelServiceFeatureRelates(long[] aProductModelServiceFeatureRelateIds)
			throws Exception {

		ProductModelServiceFeatureRelateDAOQueryBean queryBean = new ProductModelServiceFeatureRelateDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductModelServiceFeatureRelateIds);

		this.productModelServiceFeatureRelateDao.delete(queryBean);

	}

	@Override
	protected ProductModelServiceFeatureRelateBean[] doQueryProductModelServiceFeatureRelates(
			ProductModelServiceFeatureRelateDAOQueryBean queryBean) throws Exception {

		return ProductModelServiceFeatureRelateBean.toArray(this.productModelServiceFeatureRelateDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelServiceFeatureRelateCount(ProductModelServiceFeatureRelateDAOQueryBean queryBean)
			throws Exception {

		return this.productModelServiceFeatureRelateDao.queryCount(queryBean);
	}

	@Override
	protected void doSetProductModelServiceFeatureRelates(long productModelServiceId,
			ProductModelServiceFeatureRelateBean[] aProductModelServiceFeatureRelate) throws Exception {

		ProductModelServiceFeatureRelateDAOQueryBean queryBean = new ProductModelServiceFeatureRelateDAOQueryBean();

		queryBean.createCriteria().andServiceIdEqualTo(productModelServiceId);

		ProductModelServiceFeatureRelate[] serviceFeatureRelates = new ProductModelServiceFeatureRelate[aProductModelServiceFeatureRelate.length];

		for (int i = 0; i < serviceFeatureRelates.length; i++) {
			serviceFeatureRelates[i] = aProductModelServiceFeatureRelate[i].convertToProductModelServiceFeatureRelate();
			serviceFeatureRelates[i].setServiceId(productModelServiceId);
		}

		this.productModelServiceFeatureRelateDao.synchronize(serviceFeatureRelates, queryBean);

	}

	@Override
	protected ProductModelServiceFeatureRelateBean[] doGetProductModelServiceFeatureRelates(long aProductModelServiceId)
			throws Exception {

		ProductModelServiceFeatureRelateDAOQueryBean queryBean = new ProductModelServiceFeatureRelateDAOQueryBean();

		queryBean.createCriteria().andServiceIdEqualTo(aProductModelServiceId);

		return queryProductModelServiceFeatureRelates(queryBean);
	}

	@Override
	protected void doAddNewProductModelAction(ProductModelActionBean aProductModelAction) throws Exception {
		this.productModelActionDao.insert(aProductModelAction.convertToProductModelAction());
	}

	@Override
	protected void doModifyProductModelAction(ProductModelActionBean aProductModelAction) throws Exception {

		this.productModelActionDao.update(aProductModelAction.convertToProductModelAction());

	}

	@Override
	protected void doDeleteProductModelActions(long[] aProductModelActionIds) throws Exception {

		if (ArrayUtils.isEmpty(aProductModelActionIds)) {
			return;
		}

		ProductModelActionDAOQueryBean queryBean = new ProductModelActionDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductModelActionIds);

		this.productModelActionDao.delete(queryBean);

	}

	@Override
	protected ProductModelActionBean doGetProductModelActionById(long aProductModelActionId) throws Exception {

		ProductModelAction modelAction = this.productModelActionDao.findById(aProductModelActionId);

		return modelAction != null ? new ProductModelActionBean(modelAction) : null;
	}

	@Override
	protected ProductModelActionBean[] doQueryProductModelActions(ProductModelActionDAOQueryBean queryBean)
			throws Exception {

		return ProductModelActionBean.toArray(this.productModelActionDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelActionCount(ProductModelActionDAOQueryBean queryBean) throws Exception {
		return this.productModelActionDao.queryCount(queryBean);
	}

	@Override
	protected ProductModelActionBean[] doGetProductModelActions(long aProductModelId) throws Exception {

		ProductModelActionDAOQueryBean queryBean = new ProductModelActionDAOQueryBean();

		queryBean.createCriteria().andObjectIdEqualTo(aProductModelId);

		return ProductModelActionBean.toArray(this.productModelActionDao.query(queryBean));
	}

	@Override
	protected void doAddNewProductModelBase(ProductModelBaseBean aProductModelBase) throws Exception {
		this.productModelBaseDao.insert(aProductModelBase.convertToProductModelBase());
	}

	@Override
	protected ProductModelBaseBean doGetProductModelBaseById(long aProductModelBaseId) throws Exception {

		ProductModelBase modelBase = this.productModelBaseDao.findById(aProductModelBaseId);

		return modelBase != null ? new ProductModelBaseBean(modelBase) : null;
	}

	@Override
	protected void doModifyProductModelBase(ProductModelBaseBean aProductModelBase) throws Exception {

		this.productModelBaseDao.update(aProductModelBase.convertToProductModelBase());
	}

	@Override
	protected void doDeleteProductModelBases(long[] aProductModelBaseIds) throws Exception {

		if (ArrayUtils.isEmpty(aProductModelBaseIds)) {
			return;
		}

		ProductModelBaseDAOQueryBean queryBean = new ProductModelBaseDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductModelBaseIds);

		this.productModelBaseDao.deleteProductModelBaseRelate(queryBean);

		this.productModelBaseDao.delete(queryBean);

	}

	@Override
	protected ProductModelBaseBean[] doQueryProductModelBases(ProductModelBaseDAOQueryBean queryBean) throws Exception {

		return ProductModelBaseBean.toArray(this.productModelBaseDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelBaseCount(ProductModelBaseDAOQueryBean queryBean) throws Exception {
		return this.productModelBaseDao.queryCount(queryBean);
	}

	@Override
	protected void doAddNewProductModelBaseRelates(ProductModelBaseRelateBean[] aProductModelBaseRelates)
			throws Exception {

		ProductModelBaseRelate[] baseRelates = new ProductModelBaseRelate[aProductModelBaseRelates.length];

		for (int i = 0; i < baseRelates.length; i++) {
			baseRelates[i] = aProductModelBaseRelates[i].convertToProductModelBaseRelate();
		}

		this.productModelBaseRelateDao.batchInsert(baseRelates);
	}

	@Override
	protected ProductModelBaseRelateBean[] doQueryProductModelBaseRelates(ProductModelBaseRelateDAOQueryBean queryBean)
			throws Exception {

		return ProductModelBaseRelateBean.toArray(this.productModelBaseRelateDao.query(queryBean));
	}

	@Override
	protected int doQueryProductModelBaseRelateCount(ProductModelBaseRelateDAOQueryBean queryBean) throws Exception {
		return this.productModelBaseRelateDao.queryCount(queryBean);
	}

	@Override
	protected void doDeleteProductModelBaseRelates(long[] aProductModelBaseRelateIds) throws Exception {

		if (ArrayUtils.isEmpty(aProductModelBaseRelateIds)) {
			return;
		}

		ProductModelBaseRelateDAOQueryBean queryBean = new ProductModelBaseRelateDAOQueryBean();

		queryBean.createCriteria().andIdIn(aProductModelBaseRelateIds);

		this.productModelBaseRelateDao.delete(queryBean);

	}

}